home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Magazin/MacEasy 19
/
Mac Magazin and MacEasy Magazine CD - Issue 19.iso
/
Grafik & Text & Film
/
Quark XTensions
/
Freeware Xtensions
/
Scripts folder
/
Scripts
/
Text • Change Style Sheets-TEXT
< prev
Wrap
Text File
|
1994-04-15
|
5KB
|
122 lines
tell application "QuarkXPress®"
activate
try
if (exists document 1) is false then
beep
display dialog "No document is open." buttons {"Cancel"} default button 1
else
set docname to (get name of document 1)
try
--the first statement gets the name of every style sheet used in the document
set styleSheetsUsedList to get name of (style sheet of every paragraph of every story) of document 1
on error
beep
display dialog "No text with style sheets exists in this document." buttons {"Cancel"} default button 1
end try
--this gets every available style sheet in the document
set styleSheetList to get name of every style spec of document 1
--this is where we take the items from the list
--and place numbers and parens before them and a return after
--and place into another variable
set x to 1
set numberStyleSheetList to {}
repeat with i from 1 to the (count of items of styleSheetList)
set styleSheetName to item i of styleSheetList
set numberedStyleSheetName to "(" & x & ") " & styleSheetName & return
set numberStyleSheetList to numberStyleSheetList & numberedStyleSheetName
set x to x + 1
end repeat
--setting up the display dialogs so that they display within the acceptable range of characters
--then displaying the style sheet lists
--the tripFlare is so that the user has the option of repeating the list display
set styleSheetCount to the count of text items of numberStyleSheetList
set tripFlare to "Armed"
set flag to false
repeat until tripFlare is "OK"
set oldDelims to AppleScript's text item delimiters --store old delimiters
set AppleScript's text item delimiters to "," --change the delimiters to a comma
set listToDisplay to text item 1 of numberStyleSheetList
repeat with i from 2 to the (count of text items of numberStyleSheetList)
if the (count of characters of (listToDisplay & (text item i of numberStyleSheetList))) > 202 then --includes doc name
set listToDisplay to listToDisplay
display dialog "Style sheets in " & "“" & docname & "”" & ": " & return & listToDisplay buttons {"Cancel", "More"} default button 2
set listToDisplay to "" --clears the variable
end if
if (listToDisplay = "") is false then
set listToDisplay to listToDisplay & (text item i of numberStyleSheetList) --creates a list
else
set listToDisplay to (text item i of numberStyleSheetList) --starts a new screen list
end if
end repeat
--this dialog displays if there is only one screen of style sheets or as the last dialog of the series
set prompter to display dialog "Style Sheets in " & "“" & docname & "”" & ": " & return & listToDisplay buttons {"Cancel", "Again", "OK"} default button 3
-- if the user indicates to go on then ask for their choices
if button returned of prompter is "OK" then
set stylesToChange to {}
repeat until flag is true
set dialogResult to display dialog "Type the *number* of the style sheet to change FROM, " & ¬
"then a comma (,) and the *number* of the style sheet to change TO." default answer "" buttons {"Cancel", "Again", "OK"} default button 3
set tripFlare to button returned of dialogResult
if tripFlare is "Again" then
exit repeat
end if
set stylesToChange to text returned of dialogResult
--now we have to check what the user indicated for errors
set qualityCheck to "Off"
if (count of text items of stylesToChange) ≠ 2 then
display dialog "TWO styles must be chosen. One to change FROM, one to change TO."
else
try
set changeFromNumber to text item 1 of stylesToChange as integer
set changeToNumber to text item 2 of stylesToChange as integer
set qualityCheck to "Go"
on error
beep
display dialog "Type numbers only."
end try
end if
if qualityCheck is "Go" then
if changeFromNumber is greater than styleSheetCount then
display dialog "Style sheet numbers must be between 1 and " & styleSheetCount
else if changeFromNumber is 0 then
display dialog "Style sheet numbers must be between 1 and " & styleSheetCount
else if changeToNumber is greater than styleSheetCount then
display dialog "Style sheet numbers must be between 1 and " & styleSheetCount
else if changeToNumber is 0 then
display dialog "Style sheet numbers must be between 1 and " & styleSheetCount
else
set flag to true
end if
end if
end repeat
end if
set AppleScript's text item delimiters to oldDelims --set the delimiters back to the old delimiters
end repeat
--if everything is fine then do the swap of style sheets
if flag is true then
try
set styleToChangeTo to text item changeToNumber of styleSheetList
set styleToCHangeFrom to text item changeFromNumber of styleSheetList
if styleToCHangeFrom is not in styleSheetsUsedList then
beep
display dialog "The style sheet " & styleToCHangeFrom & " is not set to any text in this document." buttons "Cancel" default button 1
else
tell (every paragraph of every story of document 1 whose name of style sheet = styleToCHangeFrom)
set style sheet to styleToChangeTo
end tell
end if
beep 2
on error
end try
end if
end if
on error
end try
end tell